class Solution {
public:
    int totalMoney(int n) {
        int t = n / 7, r = n % 7;
        int a1 = 28, an = a1 + (t - 1) * 7;
        return (a1 + an) * t / 2 + ((t + 1) * 2 + r - 1) * r / 2;
    }
};